<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStoreTakePlanTable extends Migration
{
    /**
     * Run the migrations.
     * 盘点计划表
     * @return void
     */
    public function up()
    {
        $prefix = config('ibrand.app.database.prefix', 'ibrand_');
        if (!Schema::hasTable($prefix . 'store_take_plan')) {
            Schema::create($prefix . 'store_take_plan', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('shop_id');
                $table->string('name'); //盘点计划名称
                $table->string('condition')->nullable(); //盘点计划条件 json: year,season
                $table->tinyInteger('status')->default(0); //状态：0 未盘点；1 已盘点；2 作废
                $table->timestamps();
            });
        }

        if (!Schema::hasTable($prefix . 'store_take_plan_items')) {
            Schema::create($prefix . 'store_take_plan_items', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('take_stock_plan_id');
                $table->integer('base_product_id');
                $table->integer('shop_product_id');
                $table->integer('quantity')->default(0);  //当前库存量
                $table->tinyInteger('status')->default(0); //0 未盘点； 1 已盘点
                $table->timestamps();
            });
        }


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $prefix = config('ibrand.app.database.prefix', 'ibrand_');

        Schema::dropIfExists($prefix . 'store_take_plan');
        Schema::dropIfExists($prefix . 'store_take_plan_items');
    }
}
